package com.taotao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.EasyUIDataGridResult;
import com.taotao.common.pojo.EasyUITreeNode;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.pojo.TbItem;
import com.taotao.service.ItemCatService;
import com.taotao.service.ItemService;

/**
 * 商品展示视图层
 * @author leaf
 *
 */
@Controller
public class ItemController {
	@Autowired
	private ItemService itemService;
	
	@Autowired
	private ItemCatService itemCatService;
	
	@RequestMapping("/item/list")
	@ResponseBody
	public EasyUIDataGridResult getItemList(Integer page,Integer rows){
		EasyUIDataGridResult result = itemService.getItemList(page, rows);
		return result;
	}
	
	@RequestMapping("/item/cat/list")
	@ResponseBody
	public List<EasyUITreeNode> getItemCatList(@RequestParam(value="id",defaultValue="0") Long parentId ){
		List<EasyUITreeNode> list = itemCatService.getItemCatList(parentId);
		return list;
	}
	
	@RequestMapping("/item/save")
	@ResponseBody
	public TaotaoResult saveItem(TbItem item,String desc){
		TaotaoResult result = itemService.addItem(item, desc);
		return result;
	}
	
	@RequestMapping("/rest/item/delete")
	@ResponseBody
	public TaotaoResult deleteItem(String ids){
			TaotaoResult taotaoResult = itemService.deleteItem(ids);
			return taotaoResult;
	}
	
	@RequestMapping("/rest/item/instock")
	@ResponseBody
	public TaotaoResult instockItem(String ids){
		TaotaoResult taotaoResult = itemService.instockItem(ids);
		return taotaoResult;
	}
	
	@RequestMapping("/rest/item/reshelf")
	@ResponseBody
	public TaotaoResult reshelfItem(String ids){
		TaotaoResult taotaoResult = itemService.reshelfItem(ids);
		return taotaoResult;
	}
}
